package com.tanhua.demo;

import cn.hutool.core.io.FileUtil;
import com.baidu.aip.face.AipFace;
import com.baidu.aip.util.Base64Util;
import org.json.JSONObject;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashMap;

public class Demo2 {

    public static void main(String[] args) throws FileNotFoundException {

        AipFace client = new AipFace("24411970", "aEWcoErUlD8zAlOfKms9OnNE", "RMDWn9tLFz9CBAwkUZFp2kRZazL0mG3M");
        // 传入可选参数调用接口
        HashMap<String, String> options = new HashMap<String, String>();
        options.put("face_field", "age");
        options.put("max_face_num", "2");
        options.put("face_type", "LIVE");
        options.put("liveness_control", "LOW");


        String imageType = "BASE64";
        File file = new File("D:\\图文\\壁纸\\55.jpg");
        byte[] bytes = FileUtil.readBytes(file);
        String image = Base64Util.encode(bytes);

        // 人脸检测
        JSONObject res = client.detect(image, imageType, options);
        System.out.println(res.toString(2));
    }
}
